<template>
  <div class="testCheck">
    <Tabs type="card" @on-click="tabclick" value="tb2">
        <TabPane name="tb1" label="UD45">
        </TabPane>
        <TabPane name="tb2" label="MTU">
        </TabPane>
    </Tabs>
    <div class="searchDiv">
      <Form :model="searchItem" :label-width="90">
        <Row :gutter="10">
          <Col span="6">
            <FormItem label="电站">
              <Select v-model="searchItem.powerStation" clearable filterable @on-change="getHd">
                <Option
                  v-for="(item, index) in powerStationList"
                  :value="item"
                  :key="index"
                >{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="HD编号">
              <Select
                v-model="searchItem.hdNumber"
                clearable
                filterable
                :disabled="HBnumberList.length == 0"
                @on-change="getJz"
              >
                <Option v-for="(item, index) in HBnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="机组编号">
              <Select
                v-model="searchItem.aircrewNumber"
                clearable
                filterable
                :disabled="JZnumberList.length == 0"
              >
                <Option v-for="(item, index) in JZnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
             <FormItem label="参数名称">
              <Select v-model="searchItem.analyzeParam">
                <Option v-for="(item, index) in mainCode" :value="item.key">{{
                  item.name
                }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="时间">
              <DatePicker type="daterange" @on-change="changeTime"	:value="timearry" :options="options2" placement="bottom-end" placeholder="请选择时间范围" style="width:100%"></DatePicker>
            </FormItem>
          </Col>
          <Col span="12">
              <Button type="primary"  class="marRight" @click="addJz">加入对比</Button>
             <Button type="primary" class="marRight" @click="add"
              >录入数据</Button
            >
            <Upload
              style="float:left;"
              :headers="fileheader"
              :on-success="fileSuccess"
              :show-upload-list="false"
              :action="apihost + '/admin-api/admins/checkoutRecord/mtuUpload'"
            >
              <Button type="info" class="marRight">导入EXcel</Button>
            </Upload>

            <Button type="success" @click="download">导出Excel</Button>
          </Col>
        </Row>
      </Form>
      <div v-if="tagList1.length > 0" style="margin-bottom:10px;">
          <Tag
            type="border"
            color="primary"
            v-for="item in tagList1"
            :key="item"
            :name="item"
            closable
            @on-close="handleClose1"
            >{{ item }}</Tag
          >
        </div>
    </div>

    <div
      id="myChart"
      style="width:100%;height:500px;border-top:1px solid #ccc;padding-top:10px;"
    ></div>
    <Table
      :loading="loading"
      border
      :columns="columns"
      :data="tableData"
    ></Table>

    <Page
      show-total
      :total="total"
      :current="pageNo"
      :page-size="pageSize"
      style="margin:20px auto;text-align:center"
      @on-change="changePage"
    />
    <!-- 新增弹窗开始 -->
    <Modal :mask-closable="false" v-model="modal1" :title="title1" width="900" >
      <Form :label-width="75">
        <Row class="xzjz">
          <Col span="6">
            <FormItem :model="formItem" label="电站">
               <Select v-model="formItem.powerStation" clearable filterable @on-change="getHd">
                        <Option v-for="(item, index) in powerStationList" :value="item" :key="index">{{item}}</Option>
                    </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="HD编号">
               <Select v-model="formItem.hdNumber" clearable filterable :disabled="HBnumberList.length==0" @on-change="getJz">
                        <Option v-for="(item, index) in HBnumberList" :value="item" :key="index">{{item}}</Option>
                    </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="机组编号">
              <Select v-model="formItem.aircrewNumber" clearable filterable :disabled="JZnumberList.length==0">
                          <Option v-for="(item, index) in JZnumberList" :value="item" :key="index">{{item}}</Option>
                      </Select>
            </FormItem>
          </Col>
           <Col span="6">
            <FormItem label="大修号">
             <Input v-model="formItem.overhaulNo" size="small" placeholder="请输入"></Input>
            </FormItem>
          </Col>
          </Row>
          <Row class="xzjz">
          <Col span="6">
            <FormItem label="巡检时间">
             <DatePicker
                type="datetime"
                v-model="formItem.checkTime"
                @on-change="time"
                format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col>

        </Row>
      </Form>
      <div style="height:600px;overflow:auto;">
      <table width="100%" class="maintb">
        <tr>
          <th>项目</th>
          <th>监测内容</th>
          <th>名称</th>
          <th>参考值</th>
          <th>输入值</th>
        </tr>
        <tr>
          <td rowspan="4">油位</td>
          <td>曲轴箱油位</td>
          <td>150LN</td>
          <td>MIN＜L＜MAX</td>
          <td><Input v-model="formItem.crankcaseOilLevel" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>发动机驱动端轴承油位</td>
          <td>油位镜</td>
          <td>油位镜上标记</td>
          <td><Input v-model="formItem.generatorLevel" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>发动机非驱动端轴承油位</td>
          <td>油位镜</td>
          <td>油位镜上标记</td>
          <td><Input v-model="formItem.generatorLevelWrong" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>发电机轴承润滑油供给箱液位</td>
          <td></td>
          <td>MIN＜L＜MAX</td>
          <td><Input v-model="formItem.bearingSupplyLevel" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td rowspan="4">设备运行状况</td>
          <td>润滑油泵</td>
          <td>153PO</td>
          <td>正常运转</td>
          <td><Input v-model="formItem.lubricationPump" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>冷却水循环泵</td>
          <td>203PO</td>
          <td>正常运转</td>
          <td><Input v-model="formItem.fcc" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td> 冷却水电加热器</td>
          <td>202PY</td>
          <td>是否运转</td>
          <td><Input v-model="formItem.coolWaterHeater" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>风机、发电机、空压机电加热器投运</td>
          <td></td>
          <td>正常运转</td>
          <td><Input v-model="formItem.fanGenStove" size="small" placeholder="请输入"></Input></td>
        </tr>
         <tr>
          <td rowspan="8">主冷却水回路</td>
          <td>主冷却水入口温度</td>
          <td>200MT</td>
          <td><85℃</td>
          <td><Input v-model="formItem.mainCoolInletTemp" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>主冷却水出口温度</td>
          <td>201MT</td>
          <td><90℃</td>
          <td><Input v-model="formItem.mainCoolExitTemp201mt" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>主冷却水出口温度</td>
          <td>202MT</td>
          <td><90℃</td>
          <td><Input v-model="formItem.mainCoolExitTemp202mt" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>预热水温度</td>
          <td>203MT</td>
          <td>55℃≤T≤65℃</td>
          <td><Input v-model="formItem.preHotWater203mt" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>预热水温度</td>
          <td>204MT</td>
          <td>T≤65℃</td>
          <td><Input v-model="formItem.preHotWater204mt" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>A侧主冷却水压力</td>
          <td>200MP</td>
          <td>≈1.0bar</td>
          <td><Input v-model="formItem.acoolPressure" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>B侧主冷却水压力</td>
          <td>201MP</td>
          <td>≈1.0bar</td>
          <td><Input v-model="formItem.bcoolPressure" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>膨胀水箱200BA 液位</td>
          <td>200MN</td>
          <td>>308mm</td>
          <td><Input v-model="formItem.expa200baLevel" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td rowspan="5">低温冷却水回路</td>
          <td>增压空气冷却水入口温度</td>
          <td>205MT</td>
          <td><55℃</td>
          <td><Input v-model="formItem.presCoolInletTemp" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>增压空气冷却水出口温度</td>
          <td>206MT</td>
          <td><65℃</td>
          <td><Input v-model="formItem.presCoolExitTemp206mt" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>增压空气冷却水出口温度</td>
          <td>207MT</td>
          <td><70℃</td>
          <td><Input v-model="formItem.presCoolExitTemp207mt" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>增压空气冷却水压力</td>
          <td>202MP</td>
          <td>≈1.0bar</td>
          <td><Input v-model="formItem.presCoolPres" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>膨胀水箱201BA液位</td>
          <td>201MN</td>
          <td>>308mm</td>
          <td><Input v-model="formItem.expa201baLevel" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td rowspan="3"> 燃油液位</td>
          <td> 燃油储存罐001BA</td>
          <td>001MN</td>
          <td>L>4100mm</td>
          <td><Input v-model="formItem.tank001ba" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td> 燃油日用罐103BA</td>
          <td>104MN</td>
          <td>L>990mm</td>
          <td><Input v-model="formItem.fuelTank103ba" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>燃油泄漏罐102BA</td>
          <td>100MN</td>
          <td>L<150mm</td>
          <td><Input v-model="formItem.tankLeakage102ba" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td rowspan="6">润滑油</td>
          <td>润滑油入口温度</td>
          <td>150MT</td>
          <td><80℃</td>
          <td><Input v-model="formItem.lubrInletTemp150mt" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>润滑油入口压力</td>
          <td>150MP</td>
          <td>NA</td>
          <td><Input v-model="formItem.lubrInletPres150mp" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>转动部件润滑油压力</td>
          <td>152MP</td>
          <td>NA</td>
          <td><Input v-model="formItem.lubrPresRota" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>润滑油箱液位</td>
          <td>150MN</td>
          <td>>200mm</td>
          <td><Input v-model="formItem.lubrTank" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>曲轴箱液位</td>
          <td>151MN</td>
          <td>150mm≤L≤2</td>
          <td><Input v-model="formItem.crankcaseLevel151mn" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>曲轴箱液位</td>
          <td>152MN</td>
          <td>150mm≤L≤2</td>
          <td><Input v-model="formItem.crankcaseLevel152mn" size="small" placeholder="请输入"></Input></td>
        </tr>
        <tr>
          <td>压力</td>
          <td>250/251/750/751BBA</td>
          <td></td>
          <td>34≤P≤40bar</td>
          <td><Input v-model="formItem.pressure" size="small" placeholder="请输入"></Input></td>
        </tr>
      </table>
      </div>
      <div slot="footer">
               <Button @click="modal1=false">取消</Button>
              <Button type="primary" :loading="btnClick" @click="ok">确定</Button>
          </div>
    </Modal>
    <Modal :mask-closable="false"
      v-model="delmodal1"
      width="360"
      class-name="vertical-center-modal"
      @on-ok="remove()"
    >
      <p slot="header" style="color:#f60;text-align:center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认删除</span>
      </p>

      <div style="text-align:center">
        <p>确认删除此数据么？</p>
      </div>
    </Modal>
    <!-- 新增弹窗结束 -->
  </div>
</template>

<script>
import { getSelectOption, getAllPeople,getTime,getAllEqu } from "@/api/select";
import { getTableData, add, update, del, exp,echart,imp } from "@/api/testCheck2";
import { getToken } from "@/libs/util";
export default {
  data() {
    return {
      btnClick:false,
      loading:true,
      delmodal1: false,
      delId1: 0,
      peopleList: [],
      powerStationList: [],
      allEquList: [],
      allEquList2: [],
      timearry:[],
      options2: {
                    shortcuts: [
                        {
                            text: '最近一周',
                            value () {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                return [start, end];
                            }
                        },
                        {
                            text: '最近一月',
                            value () {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                return [start, end];
                            }
                        },
                        {
                            text: '最近三月',
                            value () {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                return [start, end];
                            }
                        }
                    ]
                },

      HBnumberList: [],
      JZnumberList: [],
      modal1: false,
      title1: "新增记录",
       pageNo: 1,
      pageSize: 10,
      total: 0,
       fileheader: {
        Authorization: "Bearer " + (getToken() ? getToken() : "")
      },
      colorarry: [
        "#c12e34",
        "#e6b600",
        "#0098d9",
        "#2b821d",
        "#005eaa",
        "#339ca8",
        "#a134d4",
        "#32a487",
        "#eb1e99",
        "#ff8819"
      ],
      searchItem: {
        powerStation:"",
        hdNumber:"",
        aircrewNumber: "",
        analyzeParam: "crankcaseOilLevel",
        startTime:"",
        endTime:""
      },
      formItem: {
        recordName: localStorage.getItem('recordUserName'),
      recordId:localStorage.getItem('recordUserId'),
      recordTime:getTime(),
      },
      columns: [
        {
          type: "index",
          width: 60,
          title: "序号",
          align: "center"
        },
        {
          title: "电站",
          key: "powerStation"
        },
        {
          title: "机组编号",
          key: "aircrewNumber"
        },
        {
          title: "检查日期",
          key: "checkTime"
        },
        {
          title: "记录人",
          key: "recordName"
        },
        {
          title: "记录时间",
          key: "recordTime",
          width: 150
        },
        {
          title: "操作",
          key: "action",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.edit(JSON.stringify(params));
                    }
                  }
                },
                "编辑"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.openDel(params.row.id);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      tableData: [],
      tagList1: [],
      mainCode:[
        {name:"曲轴箱油位",key:"crankcaseOilLevel"},
       {name:"发动机驱动端轴承油位",key:"generatorLevel"},
       {name:"发动机非驱动端轴承油位",key:"generatorLevelWrong"},
       {name:"发电机轴承润滑油供给箱液位",key:"bearingSupplyLevel"},
       {name:"润滑油泵",key:"lubricationPump"},
       {name:"冷却水循环泵",key:"fcc"},
       {name:" 冷却水电加热器",key:"coolWaterHeater"},
       {name:"风机、发电机、空压机电加热器投运",key:"fanGenStove"},
        {name:"主冷却水入口温度",key:"mainCoolInletTemp"},
       {name:"主冷却水出口温度",key:"mainCoolExitTemp201mt"},
       {name:"主冷却水出口温度",key:"mainCoolExitTemp202mt"},
       {name:"预热水温度",key:"preHotWater203mt"},
       {name:"预热水温度",key:"preHotWater204mt"},
       {name:"A侧主冷却水压力",key:"acoolPressure"},
       {name:"B侧主冷却水压力",key:"bcoolPressure"},
       {name:"膨胀水箱200BA 液位",key:"expa200baLevel"},
       {name:"增压空气冷却水入口温度",key:"presCoolInletTemp"},
       {name:"增压空气冷却水出口温度",key:"presCoolExitTemp206mt"},
       {name:"增压空气冷却水出口温度",key:"presCoolExitTemp207mt"},
       {name:"增压空气冷却水压力",key:"presCoolPres"},
       {name:"膨胀水箱201BA液位",key:"expa201baLevel"},
       {name:" 燃油储存罐001BA",key:"tank001ba"},
       {name:" 燃油日用罐103BA",key:"fuelTank103ba"},
       {name:"燃油泄漏罐102BA",key:"tankLeakage102ba"},
       {name:"润滑油入口温度",key:"lubrInletTemp150mt"},
       {name:"润滑油入口压力",key:"lubrInletPres150mp"},
       {name:"转动部件润滑油压力",key:"lubrPresRota"},
       {name:"润滑油箱液位",key:"lubrTank"},
       {name:"曲轴箱液位",key:"crankcaseLevel151mn"},
       {name:"曲轴箱液位",key:"crankcaseLevel152mn"},
       {name:"250/251/750/751BBA",key:"pressure"},
      ],
      option: {
        tooltip: {},
        legend: {
          data: [],
          top: "10",
          type: "scroll",
        },
        dataZoom: [],
        xAxis: {
          type: "time",
          axisLabel: {
            interval: 0,
            formatter: function(time) {
              const dateTime = new Date(time);
              const year = dateTime.getFullYear();
              const month =
                dateTime.getMonth() + 1 < 10
                  ? "0" + (dateTime.getMonth() + 1)
                  : dateTime.getMonth() + 1;
              const date =
                dateTime.getDate() < 10
                  ? "0" + dateTime.getDate()
                  : dateTime.getDate();
              const hour =  dateTime.getHours() + 1 < 10
                  ? "0" + (dateTime.getHours() + 1)
                  : dateTime.getHours() + 1;
              const minute = dateTime.getMinutes() < 10
                  ? "0" + dateTime.getMinutes()
                  : dateTime.getMinutes();
              const second = dateTime.getSeconds() < 10
                  ? "0" + dateTime.getSeconds()
                  : dateTime.getSeconds();
              return (
                year +
                "-" +
                month +
                "-" +
                date +
                " " +
                hour +
                ":" +
                minute +
                ":" +
                second
              );
            },
          },
        },
        yAxis: {
          name: "",
          type: "value",
        },
        series: [],
      },
      isChange:false
    };
  },
  methods: {
     tabclick(e){
      if(e=='tb1'){
        this.$router.push({path:'testCheck'})
      }else{
        this.$router.push({path:'testCheck2'})
      }
    },
     changeTime(e){
      this.searchItem.startTime=e[0];
      this.searchItem.endTime=e[1];
      this.$echarts.init(document.getElementById("myChart")).dispose();

      this.tagList1=[]
      this.option.legend.data=[]
      this.option.series=[]
      this.addJz();
    },
     download() {
      exp({ adminId:localStorage.getItem("recordUserId")  }).then(res => {
         const blob = new Blob([res], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;'});

        const ie = navigator.userAgent.match(/MSIE\s([\d.]+)/),
            ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/),
            ieEDGE = navigator.userAgent.match(/Edge/g),
            ieVer = (ie ? ie[1] : (ie11 ? 11 : (ieEDGE ? 12 : -1)));
        console.log('ie:' + ie);
        console.log('ieVer:' + ieVer);
        if (ie && ieVer < 10) {
            this.message.error('No blobs on IE<10');
            return;
        }
        if (ieVer > -1) {
            window.navigator.msSaveBlob(blob, '启动前检查记录MTU.xlsx');
        } else {
            const url = window.URL.createObjectURL(blob);
            let link = document.createElement('a');
            link.setAttribute('href', url);
            link.setAttribute('download', '启动前检查记录MTU.xlsx');
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }
      });
    },
    fileSuccess(response, file, fileList) {
      this.$Message.info("导入成功");
      this.getDataList();
    },
    time(e) {
      this.formItem.checkTime = e;
    },
    handleClose1(event, name) {
      this.$echarts.init(document.getElementById("myChart")).dispose();
      const index = this.tagList1.indexOf(name);
      this.tagList1.splice(index, 1);
      this.option.legend.data.splice(index, 1);
      this.option.series.splice(index, 1);
      this.$echarts.init(document.getElementById("myChart")).setOption(this.option);
    },
    addJz() {
      let that = this;
      if (this.tagList1.length > 9) {
        this.$Message.info("选择的对比已经很多了");
        return false;
      }
      if(this.searchItem.hdNumber==undefined){
        this.$Message.info("请选择HD编号");
        return false;
      }
      if(this.searchItem.aircrewNumber==undefined){
        this.$Message.info("请选择机组编号");
        return false;
      }
      echart(this.searchItem).then(res => {
          if (res.code == 0&&res.data.length>0) {
             let csname=that.mainCode.filter(item=>item.key==that.searchItem.analyzeParam)[0].name;
             if (that.tagList1.indexOf(that.searchItem.aircrewNumber+'-'+csname) == -1) {
                that.tagList1.push(that.searchItem.aircrewNumber+'-'+csname);
                that.$echarts.init(document.getElementById("myChart")).dispose();
                that.option.legend.data.push(that.searchItem.aircrewNumber+'-'+csname);
                let sjcolor = that.color16();
                let arry = [];
                for (let n = 0; n < res.data.length; n++) {
                  arry.push([res.data[n].checkTime,res.data[n][that.searchItem.analyzeParam]]);
                }
                that.option.series.push({
                  name: that.searchItem.aircrewNumber+'-'+csname,
                  data: arry,
                  type: "line",
                  smooth: true,
                  symbolSize: 8, //折线点的大小
                  itemStyle: {
                    normal: {
                      color: sjcolor, //折线点的颜色
                      lineStyle: {
                        color: sjcolor //折线的颜色
                      }
                    }
                  }
                });
                that.$echarts.init(document.getElementById("myChart")).setOption(that.option);
             }
          }else{
             that.$Message.info("此选项下无数据！");
          }
      })

    },

    color16() {
      var n = Math.floor(Math.random() * this.colorarry.length + 1) - 1;
      return this.colorarry[n];
    },
    getDataList() {
      let that = this;
      that.tableData = [];
      getTableData({ pageNo: this.pageNo, pageSize: this.pageSize })
        .then(res => {
          if (res.code == 0) {
            that.loading = false;
            that.total = res.data.total;
            that.tableData = res.data.list.sort(function(a, b) {
              return a.checkTime < b.checkTime ? 1 : -1;
            });

            that.allEquList2 = that.allEquList.filter(
              item => item.powerStation == res.data.list[0].powerStation
            );
            let arr2 = that.allEquList2.map(function(item) {
              return item.hdNumber;
            });
            that.HBnumberList = [...new Set(arr2)];

            let arr3 = that.allEquList2.filter(
              item => item.hdNumber == res.data.list[0].hdNumber
            );
            let arr4 = arr3.map(function(item) {
              return item.aircrewNumber;
            });
            that.JZnumberList = [...new Set(arr4)];

            that.searchItem.powerStation = res.data.list[0].powerStation;
            that.searchItem.hdNumber = res.data.list[0].hdNumber;
            that.searchItem.aircrewNumber = res.data.list[0].aircrewNumber;


          }
        })
        .catch(err => {
          console.error("err>" + JSON.stringify(err));
        });
    },
    getAllEqument() {
      let that=this;
      getAllEqu(null).then(res => {
        this.allEquList = res.data;
        let arr = res.data.map(function(item) {
          return item.powerStation;
        });
        this.powerStationList = [...new Set(arr)];
        this.getDataList();
        setTimeout(() => {
          that.addJz();
        }, 500);

      });
    },
    getHd(e) {
      this.JZnumberList = [];
      this.allEquList2 = this.allEquList.filter(item => item.powerStation == e);
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];
    },
    getJz(e) {
      let arr = this.allEquList2.filter(item => item.hdNumber == e);
      let arr2 = arr.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr2)];
    },
    openDel(id) {
      this.delmodal1 = true;
      this.delID1 = id;
    },
    add() {
      this.formItem = {
        recordName: localStorage.getItem('recordUserName'),
        recordId:localStorage.getItem('recordUserId'),
        recordTime:getTime()
      };
      this.isAdd = true;
      this.modal1 = true;
      this.modalTitle="录入数据"
    },
    edit(params) {
      this.modalTitle="编辑振动监测数据"
      this.formItem = JSON.parse(params).row;
      this.formItem.recordName=localStorage.getItem('recordUserName'),
      this.formItem.recordId=localStorage.getItem('recordUserId'),
      this.formItem.recordTime=getTime()
      this.isAdd = false;
      this.modal1 = true;
      this.allEquList2 = this.allEquList.filter(
        item => item.powerStation == this.formItem.powerStation
      );
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];

      let arr3 = this.allEquList2.filter(
        item => item.hdNumber == this.formItem.hdNumber
      );
      let arr4 = arr3.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr4)];
    },
    timeFormat(time) {
      if(time instanceof Date==false){
        return time
      }
      const dateTime = new Date(time);
      const year = dateTime.getFullYear();
      const month = this.addZero(dateTime.getMonth() + 1);
      const date = this.addZero(dateTime.getDate());
      const hour = this.addZero(dateTime.getHours());
      const minute = this.addZero(dateTime.getMinutes());
      const second = this.addZero(dateTime.getSeconds());
      return (
       year +
        "-" +
        month +
        "-" +
        date +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
    addZero(v) {
      return v < 10 ? "0" + v : v;
    },
    remove() {
      del({ id: this.delID1 })
        .then(res => {
          if (res.code == 0) {
            this.$Message.info("删除成功");
            this.pageNo = 1;
            this.getDataList();
          } else {
            this.$Message.info(res.message);
          }
        })
        .catch(err => {
          console.error("err>" + JSON.stringify(err));
        });
    },
    ok() {
      this.btnClick = true;
      if (this.isAdd) {
        add(this.formItem)
          .then(res => {
            if (res.code == 0) {
              this.$Message.info("新增成功");
              this.getDataList();
              this.btnClick = false;
            } else {
              this.$Message.info(res.message);
            }
          })
          .catch(err => {
            console.error("err>" + JSON.stringify(err));
          });
      } else {
        this.formItem.checkTime = this.timeFormat(
          this.formItem.checkTime
        );
        update(this.formItem)
          .then(res => {
            if (res.code == 0) {
              this.$Message.info("编辑成功");
              this.getDataList();
              this.btnClick = false;
            } else {
              this.$Message.info(res.message);
            }
          })
          .catch(err => {
            console.error("err>" + JSON.stringify(err));
          });
      }
      this.modal1 = false;
    },
    /** 分页 */
    changePage(pageNo) {
      this.pageNo = pageNo;
      this.getDataList();
    }
  },
  created() {
     let mmtime=this.options2.shortcuts[2].value();
    this.searchItem.startTime=this.timeFormat(mmtime[0]);
    this.searchItem.endTime=this.timeFormat(mmtime[1]);
    this.timearry=this.options2.shortcuts[2].value();
    this.getAllEqument();
    // 基于准备好的dom，初始化echarts实例
    let myChart = this.$echarts.init(document.getElementById("myChart"));
    // 绘制图表
    myChart.setOption(this.option);

  }
};
</script>

<style lang="less">
.testCheck {
  background: #fff;
  height: 100%;
  padding: 15px;
  font-size: 14px;
  .ivu-tabs.ivu-tabs-card > .ivu-tabs-bar .ivu-tabs-tab{
        border-radius: 0;
        background: #fff;
        margin-right:10px;
    }
  .ivu-tabs.ivu-tabs-card > .ivu-tabs-bar .ivu-tabs-tab-active{
        border-top: 2px solid #3399ff;
    }
   .ivu-tabs.ivu-tabs-card > .ivu-tabs-bar .ivu-tabs-tab-active:before{
        content: '';
        display: block;
        width: 100%;
        height: 1px;
        background: #3399ff;
        position: absolute;
        top: 0;
        left: 0;
    }
  .searchDiv {
    .marRight {
      margin-right: 15px;
    }
  }
  .ivu-form-item {
    margin-bottom: 15px;
  }
}
.baseTitle {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 10px;
}
.xzjz {
  .ivu-form-item {
    margin-bottom: 10px;
  }
}
.maintb {
    border-collapse: collapse;
  }
  .maintb td,.maintb th {
    border:1px solid #eaeaea;
    padding:5px 10px;
    text-align: center;
  }
  .maintb th {
    background:#f5f5f5;
  }
</style>
